package com.hyc.myvideo.data.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.Comment;
import com.hyc.myvideo.utils.imguitl.ImgUitl;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 留言  评论
 * Created by dfeads on 2017/8/5.
 */

public class ClassCommentAdapter extends BaseListAdapter<Comment> {

  public ClassCommentAdapter(Context context, List<Comment> objects) {
    super(context, objects);
  }

  @NonNull @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
    ClassCommentHolder holder;
    if (convertView == null) {
      if (getItemViewType(position) == 0) {
        holder = new ClassCommentHolder();
        convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
        holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
      } else {
        convertView = inflater.inflate(R.layout.item_class_comment, parent, false);
        holder = new ClassCommentHolder(convertView);
      }
      convertView.setTag(holder);
    } else {
      holder = (ClassCommentHolder) convertView.getTag();
    }

    if (hasNoData) {
      AbsListView.LayoutParams lp =
          new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
      holder.noDataRootLayout.setLayoutParams(lp);
    } else {
      Comment comment = mDataList.get(position);
      if (comment != null) {
        ImgUitl.setImg(comment.getUser_face(), holder.mImg);
        holder.mTitle.setText(comment.getUser_nickname());
        holder.mTime.setText(comment.getComment_time());
        holder.mContent.setText(comment.getComment_content());
      }
    }
    return convertView;
  }

  class ClassCommentHolder {
    public ClassCommentHolder() {
    }

    public ClassCommentHolder(View view) {
      ButterKnife.bind(this, view);
    }

    LinearLayout noDataRootLayout;

    /** 头像 */
    @BindView(R.id.item_class_comment_img) ImageView mImg;
    /** 昵称 */
    @BindView(R.id.item_class_comment_title) TextView mTitle;
    /** 时间 */
    @BindView(R.id.item_class_comment_time) TextView mTime;
    /** 内容 */
    @BindView(R.id.item_class_comment_content) TextView mContent;
  }
}
